// Copyright (C) 2008 Taylor L. Riche <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

/**
 * 
 */
package appcomp.entities;

import java.io.PrintStream;
import java.util.ArrayList;
import java.net.URI;

/**
 * @author riche
 *
 */
public class RequestGenerator extends Operator {
	
	private final String coreType;
	private final URI fileURI;
	private Type masterRequestType;
	
	/**
	 * @param name
	 * @param portList
	 */
	protected RequestGenerator(final String name, final ArrayList<Port> portList, URI fileURI, String core, ArrayList<String> methodList) {
		super(name, false, null, portList, methodList);
		this.coreType = core;
		this.fileURI = fileURI;
		for(Port p : portList) {
			if(p.getDirection().equals(Port.Direction.IN)) {
				super.setDelay(p.getName(), new Double(10));
			}
		}
	}
	public static Operator create(String name, ArrayList<Port> portList, URI f, String c, ArrayList<String> methodList) {
		return new RequestGenerator(name, portList, f, c, methodList);
	}
	
	/* (non-Javadoc)
	 * @see appcomp.entities.Operator#generateFrameworkCode(java.io.PrintStream)
	 */
	@Override
	public void generateFrameworkCode(PrintStream file) {
		file.println("\t\topVec.at(" + this.index + ") = new " + this.coreType +
		"(\"" + this.getName() + "\", arg_struct" + ");");
	}

	/* (non-Javadoc)
	 * @see appcomp.entities.Operator#generateIncludes(java.io.PrintStream)
	 */
	@Override
	public void generateIncludes(PrintStream file) {
		file.println("#include \"" + this.fileURI.toString() + "\"");
	}
	
	/* (non-Javadoc)
	 * @see appcomp.entities.Operator#doesGenerate()
	 */
	@Override
	public boolean doesGenerate() {
		return true;
	}
	/**
	 * @return the masterRequestType
	 */
	public Type getMasterRequestType() {
		return masterRequestType;
	}
	/**
	 * @param masterRequestType the masterRequestType to set
	 */
	public void setMasterRequestType(Type masterRequestType) {
		this.masterRequestType = masterRequestType;
	}

}
